package com.hc.javabasestudyproject.feature.functionalInterface;


import java.util.function.Function;

/**
 * @Author: huangcheng
 * @CreateTime: 2023-11-22  13:39
 * @Description: Function用于传入相同的对象，但是返回不同的对象
 * @Version: 1.0
 */
public class FunctionInterface {
    public static void main(String[] args) {
        FunctionInterface lambda = new FunctionInterface();
        String newStr = lambda.strHandler(" Hello Lambda!   ", new Function<String, String>() {
            @Override
            public String apply(String str) {
                return str.trim();
            }
        });
        System.out.println(newStr);

        String subStr = lambda.strHandler("Hello Lambda!", (str) -> str.substring(2, 5));
        System.out.println(subStr);

        String test = test(s -> "null","3");
    }
    //需求：用于处理字符串7 o0
    public static String strHandler(String str, Function<String, String> fun){
        return fun.apply(str);
    }

    public static <T,R> R test(Function<T,R> function,T t){
        return function.apply(t);
    }
}
